package com.afollestad.commons.simplelist;

import com.afollestad.commons.ResourceTable;
import com.afollestad.materialdialogs.utils.ResUtil;
import ohos.agp.components.element.Element;
import ohos.app.Context;

/**
 * @author Aidan Follestad (afollestad)
 */
public class MaterialSimpleListItem {
    private final Builder builder;

    private MaterialSimpleListItem(Builder builder) {
        this.builder = builder;
    }

    Element getIcon() {
        return builder.icon;
    }

    public CharSequence getContent() {
        return builder.content;
    }

    int getIconPadding() {
        return builder.iconPadding;
    }

    @Override
    public String toString() {
        if (getContent() != null) {
            return getContent().toString();
        } else {
            return "(no content)";
        }
    }

    public static class Builder {
        private final Context context;
        Element icon;
        CharSequence content;
        int iconPadding, backgroundColor;

        public Builder(Context context) {
            this.context = context;
            backgroundColor = ResUtil.getColor(context, ResourceTable.Color_normal_gray);
        }

        public Builder icon(int iconRes) {
            this.icon = ResUtil.getPixelMapDrawable(context, iconRes);
            return this;
        }

        public Builder iconPadding(int padding) {
            this.iconPadding = ResUtil.getIntDimen(context, padding);
            return this;
        }

        public Builder content(int contentRes) {
            return content(ResUtil.getString(context, contentRes));
        }

        public Builder content(CharSequence content) {
            this.content = content;
            return this;
        }

        public Builder backgroundColor(int color) {
            this.backgroundColor = ResUtil.getColor(context, color);
            return this;
        }

        public MaterialSimpleListItem build() {
            return new MaterialSimpleListItem(this);
        }
    }
}
